<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas{
            border:1px solid black;
        }
    </style>
</head>
<body>
    <canvas id="c1" width="500" height="500">该浏览器不支持该标签</canvas>
    <script>
        // 1.获取画板的DOM对象(打开画图工具)
        var c1=document.getElementById("c1");
      
        // 2.获取画笔工具(笔触)
        var ctx=c1.getContext("2d");

        ctx.beginPath();//开启路径
        //线条的颜色
        ctx.strokeStyle="red";
        ctx.moveTo(100,100);
        ctx.lineTo(100,400);
        ctx.stroke();

        ctx.beginPath();//如果不重新开启路径，颜色会覆盖
        ctx.strokeStyle="blue";
        ctx.moveTo(100,400);
        ctx.lineTo(400,400);
        ctx.lineTo(400,100);
        ctx.closePath();//连接当前路径的起始点和终点
        
        ctx.stroke();
      
    </script>

</body>
</html>